package com.hiecho;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.function.Function;

public class CustomizeClassLoad extends ClassLoader {
    public Function<String, String> path = x -> x;

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        byte[] bytes = null;
        try (FileInputStream fileInputStream = new FileInputStream("/home/hiecho/projects/hiecho-code/java-bucket/java-javassist/target/classes/" + name.replace(".", "/").concat(".class"))) {
            bytes = new byte[fileInputStream.available()];
            fileInputStream.read(bytes);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return defineClass(name, bytes, 0, bytes.length);
    }


}
